package semspe;
import javax.swing.*;
import java.awt.event.*;

class AjoutTypeAlcool extends JFrame implements ActionListener//implements WindowListener
{
	private JPanel panel;
	private JLabel numero;
	private JLabel Libellé;
	
	
	
	private JTextField txtNumero;
	private JTextField txtLibellé;
	

	
	private JOptionPane jop1;
	private JButton OK;
	private JButton annuler;
	
	public AjoutTypeAlcool()
	{
		super("Ajouter un type d'alcool");
		this.setSize(400,250);
		this.setResizable(false);
		this.setVisible(true);
		
		this.getContentPane().setLayout(null);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		this.panel = new JPanel();
		//Numero type alcool

		
		//Nom type alcool
		this.Libellé = new JLabel("Libellé :");
		this.getContentPane().add(this.Libellé);
		this.Libellé.setBounds(30,60,150,20);
		this.txtLibellé = new JTextField("");
		this.getContentPane().add(this.txtLibellé);
		this.txtLibellé.setBounds(200,60,150,20);
		
		
		
		//BUT
		this.OK = new JButton("Ajouter");
		this.getContentPane().add(this.OK);
		this.OK.setBounds(100,150,100,20);
		this.annuler = new JButton("Annuler");
		this.getContentPane().add(this.annuler);
		this.annuler.setBounds(250,150,100,20);
		
		this.annuler.addActionListener(this);
		this.OK.addActionListener(this);
		
		jop1 = new JOptionPane();
		
		
	}
	

	public void actionPerformed(ActionEvent evt) {
			if(evt.getSource() == annuler)
			this.dispose();
			else if(evt.getSource() == OK){
                            if(testType()==true){
                        String requete = "INSERT INTO typealcool VALUES ('NULL','"+this.txtLibellé.getText()+"')";
                        TraitRequete ajoutType = new TraitRequete();
                            ajoutType.ExecuteRequeteData(requete);
                            this.dispose();
                            }
                        }
	}                

        public boolean testType(){
            
                if(this.txtLibellé.getText().equals("")==false){
                    
                                      
                    return true;
                }
            
            jop1.showMessageDialog(null, "Des champs sont vides");
            return false;
        }
        
        
        public boolean testInt(String chaine) {
        try {
        int i = Integer.parseInt(chaine);
        }
        catch (Exception e) {
        return false;
        }
        return true;
        }
        
	
	public static void main (String[] a)
	{
		AjoutTypeAlcool stock1 = new AjoutTypeAlcool();
	}
	
} 
